package cn.opopopo.design_pattern_learn.结构型.proxy;

public class VideoServiceProxy implements VideoService {
    private RealVideoService realService;
    private String userRole;

    public VideoServiceProxy(String userRole) {
        this.userRole = userRole;
    }

    @Override
    public void playVideo(String videoName) {
        // 1. 权限控制
        if (!"VIP".equals(userRole) && !"Admin".equals(userRole)) {
            System.out.println("权限不足，无法播放视频: " + videoName);
            return;
        }

        // 2. 延迟初始化 + 缓存（只有真正需要时才创建真实对象）
        if (realService == null) {
            System.out.println("首次访问，创建真实视频服务...");
            realService = new RealVideoService(); // 延迟加载
        }

        // 3. 调用真实对象
        realService.playVideo(videoName);
    }
}